

package cup.modules.visual.log;

import cup.core.log.constant.EventConstant;
import cup.modules.visual.service.IVisualLogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import cup.modules.visual.entity.VisualLog;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

import java.util.Map;


/**
 * 异步监听日志事件
 *
 *
 */
@Slf4j
@AllArgsConstructor
public class VisualLogListener {

	private final IVisualLogService logService;

	@Async
	@Order
	@EventListener(VisualLogEvent.class)
	public void saveVisualLog(VisualLogEvent event) {
		Map<String, Object> source = (Map<String, Object>) event.getSource();
		VisualLog log = (VisualLog) source.get(EventConstant.EVENT_LOG);
		logService.save(log);
	}

}
